package cn.zc.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    @Bean
    public Queue periodQueue() {
        return new Queue("periodQueue", false);
    }

    @Bean
    public TopicExchange periodExchange() {
        return new TopicExchange("periodExchange");
    }

    @Bean
    public Binding binding(Queue periodQueue, TopicExchange periodExchange) {
        return BindingBuilder.bind(periodQueue).to(periodExchange).with("periodRoutingKey");
    }

    @Bean
    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
        return new RabbitTemplate(connectionFactory);
    }
}
